<?php

namespace app\admin\model;

use think\Model;
use Exception;
class TeacherEvaluation extends Model
{
    // 表名
    protected $name = 'teacher_evaluation';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = 'delete_time';

    // 追加属性
    protected $append = [
        'rating_text',
        'is_anonymous_text'
    ];
    
    public function getRatingList()
    {
        return ['1' => '很差', '2' => '差', '3' => '一般', '4' => '好', '5' => '很好'];
    }
    
    public function getIsAnonymousList()
    {
        return ['0' => '实名', '1' => '匿名'];
    }
    
    public function getRatingTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['rating']) ? $data['rating'] : '');
        $list = $this->getRatingList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getIsAnonymousTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_anonymous']) ? $data['is_anonymous'] : '');
        $list = $this->getIsAnonymousList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    /**
     * 关联学生
     */
    public function student()
    {
        return $this->belongsTo('app\\common\\model\\User', 'student_id', 'id');
    }
    
    /**
     * 关联老师
     */
    public function teacher()
    {
        return $this->belongsTo('app\\common\\model\\User', 'teacher_id', 'id');
    }
    
    /**
     * 关联班级
     */
    public function class()
    {
        return $this->belongsTo('app\\common\\model\\Classes', 'class_id', 'id');
    }
}